package com.handyshop.mall.user.controller;

import com.handyshop.mall.basic.core.vo.ResultVo;
import com.handyshop.mall.dubbo.user.entity.SysOrgUser;
import com.handyshop.mall.user.service.SysOrgUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author hs
 * @date 2020/11/19
 */
@RestController
@RequestMapping("/sysOrgUser")
@RequiredArgsConstructor
@Api(tags = "部门用户管理")
public class SysOrgUserController {

    private final SysOrgUserService sysOrgUserService;

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    public ResultVo<SysOrgUser> getById(@PathVariable Long id) {
        return ResultVo.success(sysOrgUserService.getById(id));
    }

    @PostMapping
    @ApiOperation(value = "添加")
    //@PreAuthorize("@pms.hasPermission('sys_org_user_add')")
    public ResultVo<Boolean> save(@Validated @RequestBody SysOrgUser sysOrgUser) {
        return ResultVo.success(sysOrgUserService.save(sysOrgUser));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除")
    //@PreAuthorize("@pms.hasPermission('sys_org_user_del')")
    public ResultVo<Boolean> removeById(@PathVariable Long id) {
        return ResultVo.success(sysOrgUserService.removeById(id));
    }

    @PutMapping
    @ApiOperation(value = "根据id编辑")
    //@PreAuthorize("@pms.hasPermission('sys_org_user_edit')")
    public ResultVo<Boolean> update(@Validated @RequestBody SysOrgUser sysOrgUser) {
        return ResultVo.success(sysOrgUserService.updateById(sysOrgUser));
    }

}
